package com.liner.string;

public class StringBuilderDemo {
    public static void main(String[] args) {
        //创建StringBuilder 的方式
        StringBuilder sb = new StringBuilder();//空字符串
        StringBuilder sb2 = new StringBuilder("abc");//abc串

        //String  和 StringBuilder 互转
        String str = "好好学习";
        StringBuilder sb3 = new StringBuilder(str);
        String s = sb3.toString();

        //append  追加
        sb3.append("天天向上");
        System.out.println(sb3);

        //replace  替换
        sb3.replace(0,4,"一定要好好学习"); //含头不含尾
        System.out.println(sb3);

        //delete  删除
        sb3.delete(0,4);
        System.out.println(sb3);

        //insert  增添
        sb3.insert(0,"插入的食物");
        System.out.println(sb3);

    }
}
